<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="" alt="">
    <script>
    const random = Math.floor(Math.random() * 1000)
    const api = `https://slwl-api.itheima.net/manager/captcha?key=${random}`
    const xhr = new XMLHttpRequest()
    xhr.open('get', api)
    xhr.addEventListener('readystatechange', function() {
      if (xhr.readyState !== 4) return
      if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
        document.querySelector('img').src =  xhr.responseURL
      } else {
        console.log('请求不成功')
      }
    })
    xhr.send()

    
    </script>
</body>
</html>